home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
1clickweather.js
next >
Wrap
Text File
|
2010-01-08
|
18KB
|
605 lines
// � 2005 The Weather Channel Interactive, Inc. All Rights Reserved.
// This is the main javascript source file
/*
* The ToolbarContainers hash holds objects that represent each statusbar panel.
* The key to the hash is the name of a oPanel object. The hash is created by
* looping through the array of oPanel objects creating a new ToolbarContainers
* entry for each object. The order of the panels is dictated by the order of
* the oPanel objects defined in the panel.js file.
*
*/
var ToolbarContainers = {};
var DataContainers = {};
var XULSimple = null;
var GlobalError = null;
var GlobalNetworkError = null;
var GlobalToolbarLocation = null;
var GlobalInitFinished = false;
var GlobalInitTime = now();
var GlobalDisablePopup = false;
var GlobalConfigObserver = null;
var GlobalWindow = null;
var extensionUninstalled = false;
// TODO: Get this value from config
// The next code catch the item-uninstalled data from em-action-requested
const MY_EXTENSION_UUID = "{DCBD1271-D228-4082-9FBC-36D9B7660B03}";
function initializeOverlay(){
UninstallObserver.register();
}
var UninstallObserver = {
/* this script was get */
_uninstall : false,
observe: function(subject, topic, data){
if (topic == "em-action-requested") {
subject.QueryInterface(Components.interfaces.nsIUpdateItem);
if (subject.id == MY_EXTENSION_UUID) {
if (data == "item-uninstalled") {
this._uninstall = true;
extensionUninstalled = true;
}
else if (data == "item-cancel-action") {
this._uninstall = false;
extensionUninstalled = false;
var track= new weather_trackingSystem();
track.sendAnalyticusTag(5); // Enabled ??
}
else if(data == "item-disabled"){
var track= new weather_trackingSystem();
track.sendAnalyticusTag(4); // Disabled
this._uninstall = false;
extensionUninstalled = false;
}
}
}
// Uninstall tag throw from here to grant quit application
// avoiding disable action
//else if (topic == "item-uninstalled") {
else if(topic == "quit-application-granted") {
//alert("goodby with: " + this._uninstall);
this.unregister();
}
},
register:function(){
var observerservice = Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerservice.addObserver(this,"em-action-requested",false);
observerservice.addObserver(this,"item-uninstalled",false);
},
unregister:function(){
var observerservice = Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerservice.removeObserver(this,"em-action-requested");
observerservice.removeObserver(this,"item-uninstalled");
}
}
function goShutdown() {
if(this.extensionUninstalled){
var track= new weather_trackingSystem();
track.sendAnalyticusTag(3); // Uninstall
}
}
// XXX bclary
var GlobalInitCount = 0;
// this is effectivly our 'main()' function that starts up everything
function goInit() {
if(GlobalInitFinished){
return false;
}
// XXX bclary
// TODO: Review this.
// Increment GlobalInitCount calling goInit if the first time
++GlobalInitCount;
if(GlobalInitCount == 1){
setTimeout(goInit,500);
return false;
}
jsInclude("chrome://1clickweather/content/js/utils/definitions.js");
jsInclude("chrome://1clickweather/content/js/utils/xul.js");
jsInclude("chrome://1clickweather/content/js/utils/errorhandler.js");
jsInclude("chrome://1clickweather/content/js/utils/appconstants.js");
jsInclude("chrome://1clickweather/content/js/utils/datadumper.js");
jsInclude("chrome://1clickweather/content/js/utils/configupdateobserver.js");
jsInclude("chrome://1clickweather/content/js/utils/network.js");
jsInclude("chrome://1clickweather/content/js/config/loadconfig.js");
jsInclude("chrome://1clickweather/content/js/trackingsystem.js");
// load up data javascript
jsInclude("chrome://1clickweather/content/js/data/datasource.js");
jsInclude("chrome://1clickweather/content/js/data/panel.js");
/* This is the block 1*/
try{
GlobalWindow = window;
XULSimple = new oXULSimple;
GlobalError = new oErrorHandler;
GlobalNetworkError = new oNetworkErrorHandler;
}catch(e){
alert(e);
}
/* Block 2*/
// create an observer to listen for config changes
try {
GlobalConfigObserver = new ConfigUpdateObserver();
GlobalConfigObserver.setFunction(userConfigUpdate);
GlobalConfigObserver.register();
}catch(e) {
debug("config update ocreatebserver: " + e);
}
/* Block 3*/
try {
var d = new ConfigUpdateObserver("debugupdate");
d.setFunction(createDebugPanel);
d.register();
}catch(e) {
debug("debug observer: " + e);
}
/* Block 4 */
try{
jsInclude("chrome://1clickweather/content/js/data/search.js");
loadSearch();
}catch(e){
debug("error init search: " + e);
}
try{
// fire up the config system.
// loadconfig.js can be included where ever you need access to config variables.
// it will pop GlobalUserConfig and GlobalAppConfig into existance
// the first thing we do with the config is find the location we should put things in the browser
GlobalToolbarLocation = ToolbarLocations[GlobalUserConfig.getAllProfiles().getDefaultProfile().getSetup().getPosition()];
if(GlobalToolbarLocation == "undefined"){
GlobalToolbarLocation = ToolbarLocations["StatusBar"];
}
}catch(e){
debug("error loading config: " + e);
}
// first, we loop through the datasource objects making them as we go
for(var i in oDataSources){
if (i == "Fcst" || i == "Obs")
DataContainers[i] = window[i];
else
DataContainers[i] = create_class("oDataSources." + i);
var tmpId = DataContainers[i].Id(i);
}
// ok, we loop through the panel object array making new panels
/*
for(var i in oPanel){
*/
for(i in oPanel){
if (i == "Fcst" || i == "Obs")
ToolbarContainers[i] = window[i];
else
ToolbarContainers[i] = create_class("oPanel." + i);
var tmpInit = ToolbarContainers[i].init(i);
}
//**-- We show the toolbar location, because it can be hidden!
if(document.getElementById(GlobalToolbarLocation).hidden)
document.getElementById(GlobalToolbarLocation).hidden = false;
// if this is the initial setup, fire up the config system
// get unique user id from weather unique id service
if(GlobalUserConfig.getInfo().getIsInitial() == "true"){
// call getUniqueUserId to get user id from weather servers
var track = new weather_trackingSystem();
track.getUniqueUserId();
// re prevent any popups from happening when we reconfig the system
GlobalInitFinished = false;
// open setup dialog
callSetup(true);
}
else
{
// otherwise, just show everything as normal
configIcons();
setupCC();
setupFcst();
setupSWA();
}
}
// we work our way through the icons in the options panel hiding or showing them based on the config
function configIcons(){
try{
debug('changing icons');
if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getLifeStyle().getIsEnabled() == "true"){
// ToolbarContainers['Options'].ShowIcon('lifestyle');
ToolbarContainers['Options'].ShowIcon('hourbyhour');
ToolbarContainers['Options'].ShowIcon('tendayfcst');
}else{
// ToolbarContainers['Options'].HideIcon('lifestyle');
ToolbarContainers['Options'].HideIcon('hourbyhour');
ToolbarContainers['Options'].HideIcon('tendayfcst');
}
if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getRadar().getIsEnabled() == "true"){
ToolbarContainers['Options'].ShowIcon('radar');
// Set image url to reflect the user selection
setRadarImageUrl();
}else{
ToolbarContainers['Options'].HideIcon('radar');
}
if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getSatelite().getIsEnabled() == "true"){
ToolbarContainers['Options'].ShowIcon('satellite');
// Set image url to reflect the user selection
setSatelliteImageUrl();
}else{
ToolbarContainers['Options'].HideIcon('satellite');
}
if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getVideo().getIsEnabled() == "true"){
ToolbarContainers['Options'].ShowIcon('video');
}else{
ToolbarContainers['Options'].HideIcon('video');
}
}catch(e){
debug("show/hide icons: " + e);
}
}
/* setupCC */
function setupCC(){
if(typeof(DataContainers['Obs']) == "object"){
var dataUrl = "";
try {
var configUtils = new ConfigUtils();
dataUrl = configUtils.getUrl(GlobalAppConfig, GlobalUserConfig, "Obs");
}catch(e){
debug(e);
}
/* Set url to Obs and set refresh interval */
DataContainers['Obs'].Url(dataUrl);
DataContainers['Obs'].setInterval(GlobalAppConfig.getDataByName("Obs").getUpdateInterval().getTime());
}else{
debug("no DataContainers obs");
}
/* if obs is enabled, update and start */
if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getCurrentCond().getIsEnabled() == "true"){
DataContainers['Obs'].Update();
DataContainers['Obs'].Start();
}
}
function deleteCC(){
ToolbarContainers['CurrentCond'].Hide();
DataContainers['Obs'].Shutdown();
delete(DataContainers['Obs']);
}
function setupFcst(){
if(typeof(DataContainers['Fcst']) == "object"){
var dataUrl = "";
try {
var configUtils = new ConfigUtils();
dataUrl = configUtils.getUrl(GlobalAppConfig, GlobalUserConfig, "Fcst");
}catch(e){
debug(e);
}
DataContainers['Fcst'].Url(dataUrl);
DataContainers['Fcst'].setInterval(GlobalAppConfig.getDataByName("Fcst").getUpdateInterval().getTime());
}else{
debug("no DataContainers fcst");
}
/* update and start */
if((GlobalUserConfig.getAllProfiles().getDefaultProfile().getForecast().getIsEnabled() == "true") ||
(GlobalUserConfig.getAllProfiles().getDefaultProfile().getExtForecast().getIsEnabled() == "true")){
DataContainers['Fcst'].Update();
DataContainers['Fcst'].Start();
}
}
function deleteFcst(){
ToolbarContainers['Day0'].Hide();
ToolbarContainers['Day1'].Hide();
ToolbarContainers['Day2'].Hide();
ToolbarContainers['Day3'].Hide();
ToolbarContainers['Day4'].Hide();
DataContainers['Fcst'].Shutdown();
delete(DataContainers['Fcst']);
}
function setupSWA(){
//alert("setupSwa");
if(typeof(DataContainers['SWA']) == "object"){
var dataUrl = "";
try {
var configUtils = new ConfigUtils();
dataUrl = configUtils.getUrl(GlobalAppConfig, GlobalUserConfig, "SWA");
}catch(e){
debug(e);
}
DataContainers['SWA'].Url(dataUrl);
// setup the scheduler to run severe weather calls based on the interval in minutes in the config
DataContainers['SWA'].setInterval(GlobalUserConfig.getAllProfiles().getDefaultProfile().getCurrentCond().getAlerts().getInterval());
}else{
debug("no DataContainers swa");
}
if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getCurrentCond().getAlerts().getIsEnabled() == "true"){
DataContainers['SWA'].Update();
DataContainers['SWA'].Start();
setTimeout(setGlobalInitFinished, 3500);
}
}
function deleteSWA(){
ToolbarContainers['SWA'].Hide();
DataContainers['SWA'].Shutdown();
delete(DataContainers['SWA']);
}
// when we get a message from the config screen, we delete then recreate everything
function userConfigUpdate(subject, topic, data){
debugLog("reconfigure due to save");
// re prevent any popups from happening when we reconfig the system
GlobalInitFinished = false;
try{
deleteCC();
deleteFcst();
deleteSWA();
}catch(e){
debugLog("error doing initial deletes: " + e);
}
try{
var cfgManager = new ConfigManager();
tmpUserCfg = new cfgManager.getUserConfig();
delete(GlobalUserConfig);
GlobalUserConfig = tmpUserCfg;
// the first thing we do with the config is find the location we should put things in the browser
GlobalToolbarLocation = ToolbarLocations[GlobalUserConfig.getAllProfiles().getDefaultProfile().getSetup().getPosition()];
if(GlobalToolbarLocation == "undefined"){
GlobalToolbarLocation = ToolbarLocations["StatusBar"];
}
DataContainers = {};
// first, we loop through the datasource objects making them as we go
for(var i in oDataSources){
if (i == "Fcst" || i == "Obs")
DataContainers[i] = window[i];
else
DataContainers[i] = create_class("oDataSources." + i);
var tmpId = DataContainers[i].Id(i);
}
}catch(e){
debugLog("error reloading user data: " + e);
}
ToolbarContainers['SWA'].moveToolbar();
ToolbarContainers['Options'].moveToolbar();
ToolbarContainers['CurrentCond'].moveToolbar();
ToolbarContainers['Day0'].moveToolbar();
ToolbarContainers['Day1'].moveToolbar();
ToolbarContainers['Day2'].moveToolbar();
ToolbarContainers['Day3'].moveToolbar();
ToolbarContainers['Day4'].moveToolbar();
// update icons in the options panel
var ccc = configIcons();
setTimeout(runDataConfig, 1000);
debugLog("done with reconfigure");
//alert("Notice:\n\nYour 1-ClickWeather settings have been saved!\n\nThank You.\n\n");
// we wait for a few seconds before we turn on the already initialized flag
// that way, we don't show tooltips right off
setTimeout(setGlobalInitFinished, 4000);
return true;
}
function create_class(class) {
return new Function('return new ' + class)();
};
function setGlobalInitFinished(){
GlobalInitFinished = true;
}
function runDataConfig() {
// update icons in the options panel
var ccc = configIcons();
try{
// deleteCC();
setupCC();
// deleteFcst();
setupFcst();
// deleteSWA();
setupSWA();
}catch(e){
debugLog("error doing initial setups: " + e);
}
}
/* callSetup methods */
function callSetup(initial){
var networkError = false;
var cz = null;
// default location
var loc = GlobalUserConfig.getAllProfiles().getDefaultProfile().getSetup().getLocation().getLocID();
/* TODO: Review this code */
if(loc == "default"){ // if we had to set a default location because it's a new install
loc = "30339"; // default location ??
networkError = true; // TODO: why this flag is set to true ??
}
/* TODO: Review this. Its neccessary*/
var locStr = GlobalSearch.getLocationData(loc);
if(locStr){
if(initial){
cz = openXUL("config.xul","setup","initial");
}else{
cz = openXUL("config.xul");
}
}else{
// depending on if we are already configured or if it's a fresh install, show the right popup error
if(networkError){
debugLog("network error in callSetup");
GlobalNetworkError.Show();
}else{
debugLog("network error in callSetup at new install");
GlobalError.Show();
}
}
}
//***************************************************************
//Image Int�l Satellite Maps
function setSatelliteImageUrl(){
// get radar id
var rid = GlobalUserConfig.getAllProfiles().getDefaultProfile().getSatelite().getID();
// get radar image reference
var satelliteImg = document.getElementById("satelliteImage");
var r = "";
switch(rid){
case "satelliteEurope":
r = "http://bd.image.weather.com/images/sat/europesat_277x187.jpg";
break;
case "satelliteMiddleEast":
r = "http://bd.image.weather.com/images/sat/mideastsat_277x187.jpg";
break;
case "satelliteMexico":
r = "http://bd.image.weather.com/images/sat/mexsat_277x187.jpg";
break;
case "satelliteRussia":
r = "http://bd.image.weather.com/images/sat/russia_sat_277x187.jpg";
break;
case "satelliteAfrica":
r = "http://bd.image.weather.com/images/sat/africasat_277x187.jpg";
break;
case "satelliteCentralAmerica":
r = "http://bd.image.weather.com/images/sat/cenamersat_277x187.jpg";
break;
case "satelliteAsia":
r = "http://bd.image.weather.com/images/sat/asiasat_277x187.jpg";
break;
case "satelliteCanada":
r = "http://bd.image.weather.com/images/sat/canadasat_277x187.jpg";
break;
case "satelliteSouthAmerica":
r = "http://bd.image.weather.com/images/sat/sasat_277x187.jpg";
break;
}
// set src attribute to reflect the user selection
satelliteImg.setAttribute("src",r);
}
/* get image url from radar id */
function setRadarImageUrl(){
// get radar id
var rid = GlobalUserConfig.getAllProfiles().getDefaultProfile().getRadar().getID();
// get radar image reference
var dopplerImg = document.getElementById("dopplerImage");
var r = "";
switch(rid){
case "radarNorthwest":
r = "http://bd.image.weather.com/web/radar/us_nw_9regradar_small_usen.jpg";
break;
case "radarNorthcentral":
r = "http://bd.image.weather.com/web/radar/us_nc_9regradar_small_usen.jpg";
break;
case "radarNortheast":
r = "http://bd.image.weather.com/web/radar/us_ne_9regradar_small_usen.jpg";
break;
case "radarWestcentral":
r = "http://bd.image.weather.com/web/radar/us_wc_9regradar_small_usen.jpg";
break;
case "radarCentral":
r = "http://bd.image.weather.com/web/radar/us_cn_9regradar_small_usen.jpg";
break;
case "radarEastcentral":
r = "http://bd.image.weather.com/web/radar/us_ec_9regradar_small_usen.jpg";
break;
case "radarSouthwest":
r = "http://bd.image.weather.com/web/radar/us_sw_9regradar_small_usen.jpg";
break;
case "radarSouthcentral":
r = "http://bd.image.weather.com/web/radar/us_sc_9regradar_small_usen.jpg";
break;
case "radarSoutheast":
r = "http://bd.image.weather.com/web/radar/us_se_9regradar_small_usen.jpg";
break;
}
// set src attribute to reflect the user selection
dopplerImg.setAttribute("src",r);
}